library(stargazer)
library(dplyr)
library(tidyr)
library(ggplot2)
library(tibble)
rm(list = ls())

theme_set(theme_grey())

# READ DATA
# =========

# MAKE SURE TO USE 'SETWD' TO SET THE DIRECTORY WHERE 
# THE REPLICATION FILES HAVE BEEN DONWLOADED

#setwd("[REPLICATION MATERIALS PATH]")

df<-read.csv("ug_replication_data.csv")

# 1. REPLICATION CODE FOR MANUSCRIPT TABLES AND FIGURES
# =====================================================
# =====================================================

# TABLES
# ======

# TABLE 1: DESCRIPTIVE STATISTICS 
# ===============================

# Table created in latex; data used is extracted from the following tabulations / summary commands:

    # sex, age groups, educ, tenure / gov. exp, party ID
      # sex, pols only
    prop.table(table(df$sex[!is.na(df$ug_propose)&df$pol==1],df$country[!is.na(df$ug_propose)&df$pol==1]),2)
      # age categories, pols only
    prop.table(table(df$age_cat[!is.na(df$ug_propose)&df$pol==1],df$country[!is.na(df$ug_propose)&df$pol==1]),2)
      # tenure/exp
    df %>%
      group_by(country)%>%
      filter(!is.na(ug_propose)) %>%
      summarise(tenure_mean = mean(tenure,na.rm=TRUE),gov_exp_mean = mean(gov_exp,na.rm = TRUE))
    

# TABLE 2: PROPOSALS AND DEMANDS MADE BY POLITICIANS IN THE ULTIMATUM GAME
# ========================================================================
    
ug_toplines_all<-df %>%
  filter(!is.na(ug_propose)) %>%
  summarise(country_name="All",propose_mean = mean(ug_propose,na.rm=TRUE),accept_mean= mean(ug_accept,na.rm=TRUE),n())

ug_toplines<-df %>%
  filter(!is.na(ug_propose)) %>%
  group_by(country_name) %>%
  summarise(propose_mean = mean(ug_propose,na.rm=TRUE),accept_mean= mean(ug_accept,na.rm=TRUE),n()) 

ug_toplines<-bind_rows(ug_toplines_all,ug_toplines)

# output table
stargazer(as.data.frame(ug_toplines),summary=FALSE,single.row = TRUE,
          table.placement = "H",label = "ug_toplines", digits=0,rownames = FALSE,
          covariate.labels = c("Sample","Country","Mean Proposal","Mean Demand","N"))


# TABLE 3: MAIN REGRESSION ESTIMATION RESULTS
# ===========================================

# models used in the table, by order
m_all_p<-lm(data=subset(df,pol==1),ug_propose ~ ug_p2_copartisan + ug_propose_first + country)
m_all_p_p2p<-lm(data=subset(df,pol==1),ug_propose ~ ug_p2_copartisan + ug_p2_politician + ug_propose_first + country)
m_all_a<-lm(data=subset(df,pol==1),ug_accept ~ ug_p2_copartisan + ug_propose_first + country)
m_all_a_p2p<-lm(data=subset(df,pol==1),ug_accept ~ ug_p2_copartisan + ug_p2_politician + ug_propose_first + country)

# output table
stargazer(m_all_p,
          m_all_p_p2p,
          m_all_a,
          m_all_a_p2p,
          single.row = FALSE,no.space = TRUE,model.numbers = FALSE,
          dep.var.caption = "",dep.var.labels.include = FALSE,
          table.placement = "H",label = "h1_h2_models_all", digits=2,
          omit.stat = c("rsq","ser","f"),
          column.labels = c("DV: Proposal","DV: Demand"),
          column.separate=c(2,2),
          covariate.labels = c("Co-partisan Target","Politician Target","Propose First",
                               "Canada (FE)","Switzerland (FE)","Germany (FE)","United States (FE)","Intercept"))


# TABLE 4: PARTISANSHIP TREATMENT EFFECTS BY PARTY
# ================================================

ug_p2_copartisan_all_nocountry<-df %>%
  filter(!is.na(ug_propose)) %>%
  filter(pol==1) %>%
  group_by(ug_p2_copartisan_labelled) %>%
  dplyr::summarise(country_name="All",propose_mean = mean(ug_propose,na.rm=TRUE),
                   accept_mean= mean(ug_accept,na.rm=TRUE),
                   N = n())  %>%
  na.omit() 
ug_p2_copartisan_all_nocountry<-ug_p2_copartisan_all_nocountry[,c(2,1,3,4,5)]
ug_p2_copartisan_all_nocountry$N<-as.character(ug_p2_copartisan_all_nocountry$N)

difference_p2_copartisan_all_nocountry <- ug_p2_copartisan_all_nocountry %>%
  mutate(propose_mean = propose_mean - lag(propose_mean),
         accept_mean = accept_mean - lag(accept_mean),
         ug_p2_copartisan_labelled = "Difference",
         N = "-") %>%
  na.omit() 

ug_p2_copartisan_all_nocountry<-ug_p2_copartisan_all_nocountry %>%
  bind_rows(difference_p2_copartisan_all_nocountry) 

ug_p2_copartisan_all<-df %>%
  filter(!is.na(ug_propose)) %>%
  filter(pol==1) %>%
  group_by(country_name,ug_p2_copartisan_labelled) %>%
  dplyr::summarise(propose_mean = mean(ug_propose,na.rm=TRUE),
                   accept_mean= mean(ug_accept,na.rm=TRUE),
                   N = n())  %>%
  na.omit() 

ug_p2_copartisan_all$N<-as.character(ug_p2_copartisan_all$N)

difference_p2_copartisan_all <- ug_p2_copartisan_all %>%
  group_by(country_name) %>%
  mutate(propose_mean = propose_mean - lag(propose_mean),
         accept_mean = accept_mean - lag(accept_mean),
         ug_p2_copartisan_labelled = "Difference",
         N = "-") %>%
  na.omit() 

ug_p2_copartisan_all<-ug_p2_copartisan_all %>%
  bind_rows(difference_p2_copartisan_all) %>%
  arrange(country_name)

ug_p2_copartisan_all<-bind_rows(ug_p2_copartisan_all_nocountry,ug_p2_copartisan_all)
ug_p2_copartisan_all$country_name<-as.character(ug_p2_copartisan_all$country_name)
ug_p2_copartisan_all$country_name[ug_p2_copartisan_all$ug_p2_copartisan_labelled=="Out-Partisan"|ug_p2_copartisan_all$ug_p2_copartisan_labelled=="Difference"]<-" "

# output table
stargazer(as.data.frame(ug_p2_copartisan_all),summary=FALSE,single.row = TRUE,
          table.placement = "H",label = "ug_p2_outpartisan_all", digits=0,rownames = FALSE,
          covariate.labels = c("Country","Target","Mean Proposal","Mean Demand","N"))


# TABLE 5: INTERACTION ESTIMATION RESULTS
# =======================================

m_interaction_propose_all<-lm(data=subset(df,pol==1),ug_propose ~ ug_p2_politician* ug_p2_copartisan + ug_propose_first + country)
m_interaction_accept_all<-lm(data=subset(df,pol==1),ug_accept ~ ug_p2_politician* ug_p2_copartisan + ug_propose_first + country)

# output table
stargazer(m_interaction_propose_all,
          m_interaction_accept_all,
          single.row = FALSE,no.space = TRUE,model.numbers = FALSE,
          dep.var.caption = "",dep.var.labels.include = FALSE,
          table.placement = "H",label = "m_interactions", digits=2,
          omit.stat = c("rsq","ser","f"),
          column.labels = c("DV: Proposal","DV: Demand"),
          column.separate=c(2,2),
          covariate.labels = c("Politician Target","Co-partisan Target","Propose First",
                               "Canada (FE)","Switzerland (FE)","Germany (FE)","United States (FE)","Intercept"))


# FIGURES
# =======

# FIGURE 1: PROPOSALS AND DEMANDS MADE BY POLITICIANS IN THE ULTIMATUM GAME
# =========================================================================

ug_toplines_prop<-df %>%
  filter(!is.na(ug_propose)) %>%
  group_by(country_name) %>%
  summarise(mean = mean(ug_propose,na.rm=TRUE),n()) 
ug_toplines_prop_all<-df %>%
  filter(!is.na(ug_propose)) %>%
  summarise(mean = mean(ug_propose,na.rm=TRUE),n()) %>%
  mutate(country_name="All")
ug_toplines_acce<-df %>%
  filter(!is.na(ug_propose)) %>%
  group_by(country_name) %>%
  summarise(mean = mean(ug_accept,na.rm=TRUE),n()) 
ug_toplines_acce_all<-df %>%
  filter(!is.na(ug_accept)) %>%
  summarise(mean = mean(ug_accept,na.rm=TRUE),n()) %>%
  mutate(country_name="All")
ug_toplines_prop$dv<-"Proposals"
ug_toplines_acce$dv<-"Demands"
ug_toplines_prop_all$dv<-"Proposals"
ug_toplines_acce_all$dv<-"Demands"

ug_toplines<-ug_toplines_prop_all %>%
  bind_rows(ug_toplines_prop,ug_toplines_acce_all,ug_toplines_acce)

toplines_means_plot <- ggplot(data=ug_toplines)+
  geom_hline(aes(yintercept=500),linetype="dashed",size=0.5)+
  geom_col(aes(x=country_name,y=mean,fill=reorder(dv, desc(dv))),position="dodge2")+
  scale_colour_manual(values = c("royalblue4","darkorange2"))+
  scale_fill_manual(values = c("royalblue4","darkorange2"))+
  scale_y_continuous(limits=c(0,750),breaks=c(0,100,200,300,400,500,600,700))+
  labs(fill = "Outcome")+
  theme(axis.text = element_text(size=12),
        legend.text = element_text(size=12),
        legend.title = element_text(size = 14))+
  xlab("")+
  ylab("")
toplines_means_plot
ggsave("toplines_means_plot.eps",toplines_means_plot)
ggsave("toplines_means_plot.pdf",toplines_means_plot)

# FIGURE 2: PARTISANSHIP TREATMENT EFFECTS BY COUNTRY 
# ===================================================

# create data frame containing relevant estimates and confidence intervals
Country <- rep(c("All","Belgium","Canada","Germany","Switzerland","United States"),4)
Quantity <- c(rep("Proposal",12),rep("Demand",12))
Sample <- rep(c(rep("Politicians",12)),2)
Target <- rep(c(rep("Politician/Citizen",6),rep("Co-Partisan/Out-Partisan",6)),2)
value <- rep(NA,24)
cilo <- rep(NA,24)
cihi <- rep(NA,24)

effect_sizes <- data.frame(Country,Quantity,Sample,Target,value,cilo,cihi)

# extract values of quantity change in proposals and demands by partisanship treatment condition, for each country and for the pooled sampled

t_prop_pol_pceffect_all<-t.test(df$ug_propose[df$ug_p2_politician==1&df$pol==1],df$ug_propose[df$ug_p2_politician==0&df$pol==1])
t_prop_pol_coeffect_all<-t.test(df$ug_propose[df$ug_p2_copartisan==1&df$pol==1],df$ug_propose[df$ug_p2_copartisan==0&df$pol==1])
t_acce_pol_pceffect_all<-t.test(df$ug_accept[df$ug_p2_politician==1&df$pol==1],df$ug_accept[df$ug_p2_politician==0&df$pol==1])
t_acce_pol_coeffect_all<-t.test(df$ug_accept[df$ug_p2_copartisan==1&df$pol==1],df$ug_accept[df$ug_p2_copartisan==0&df$pol==1])

t_prop_pol_pceffect_be<-t.test(df$ug_propose[df$ug_p2_politician==1&df$pol==1&df$country=="BE"],df$ug_propose[df$ug_p2_politician==0&df$pol==1&df$country=="BE"])
t_prop_pol_pceffect_ca<-t.test(df$ug_propose[df$ug_p2_politician==1&df$pol==1&df$country=="CA"],df$ug_propose[df$ug_p2_politician==0&df$pol==1&df$country=="CA"])
t_prop_pol_pceffect_de<-t.test(df$ug_propose[df$ug_p2_politician==1&df$pol==1&df$country=="DE"],df$ug_propose[df$ug_p2_politician==0&df$pol==1&df$country=="DE"])
t_prop_pol_pceffect_ch<-t.test(df$ug_propose[df$ug_p2_politician==1&df$pol==1&df$country=="CH"],df$ug_propose[df$ug_p2_politician==0&df$pol==1&df$country=="CH"])
t_prop_pol_pceffect_us<-t.test(df$ug_propose[df$ug_p2_politician==1&df$pol==1&df$country=="US"],df$ug_propose[df$ug_p2_politician==0&df$pol==1&df$country=="US"])
t_prop_pol_coeffect_be<-t.test(df$ug_propose[df$ug_p2_copartisan==1&df$pol==1&df$country=="BE"],df$ug_propose[df$ug_p2_copartisan==0&df$pol==1&df$country=="BE"])
t_prop_pol_coeffect_ca<-t.test(df$ug_propose[df$ug_p2_copartisan==1&df$pol==1&df$country=="CA"],df$ug_propose[df$ug_p2_copartisan==0&df$pol==1&df$country=="CA"])
t_prop_pol_coeffect_de<-t.test(df$ug_propose[df$ug_p2_copartisan==1&df$pol==1&df$country=="DE"],df$ug_propose[df$ug_p2_copartisan==0&df$pol==1&df$country=="DE"])
t_prop_pol_coeffect_ch<-t.test(df$ug_propose[df$ug_p2_copartisan==1&df$pol==1&df$country=="CH"],df$ug_propose[df$ug_p2_copartisan==0&df$pol==1&df$country=="CH"])
t_prop_pol_coeffect_us<-t.test(df$ug_propose[df$ug_p2_copartisan==1&df$pol==1&df$country=="US"],df$ug_propose[df$ug_p2_copartisan==0&df$pol==1&df$country=="US"])

t_acce_pol_pceffect_be<-t.test(df$ug_accept[df$ug_p2_politician==1&df$pol==1&df$country=="BE"],df$ug_accept[df$ug_p2_politician==0&df$pol==1&df$country=="BE"])
t_acce_pol_pceffect_ca<-t.test(df$ug_accept[df$ug_p2_politician==1&df$pol==1&df$country=="CA"],df$ug_accept[df$ug_p2_politician==0&df$pol==1&df$country=="CA"])
t_acce_pol_pceffect_de<-t.test(df$ug_accept[df$ug_p2_politician==1&df$pol==1&df$country=="DE"],df$ug_accept[df$ug_p2_politician==0&df$pol==1&df$country=="DE"])
t_acce_pol_pceffect_ch<-t.test(df$ug_accept[df$ug_p2_politician==1&df$pol==1&df$country=="CH"],df$ug_accept[df$ug_p2_politician==0&df$pol==1&df$country=="CH"])
t_acce_pol_pceffect_us<-t.test(df$ug_accept[df$ug_p2_politician==1&df$pol==1&df$country=="US"],df$ug_accept[df$ug_p2_politician==0&df$pol==1&df$country=="US"])
t_acce_pol_coeffect_be<-t.test(df$ug_accept[df$ug_p2_copartisan==1&df$pol==1&df$country=="BE"],df$ug_accept[df$ug_p2_copartisan==0&df$pol==1&df$country=="BE"])
t_acce_pol_coeffect_ca<-t.test(df$ug_accept[df$ug_p2_copartisan==1&df$pol==1&df$country=="CA"],df$ug_accept[df$ug_p2_copartisan==0&df$pol==1&df$country=="CA"])
t_acce_pol_coeffect_de<-t.test(df$ug_accept[df$ug_p2_copartisan==1&df$pol==1&df$country=="DE"],df$ug_accept[df$ug_p2_copartisan==0&df$pol==1&df$country=="DE"])
t_acce_pol_coeffect_ch<-t.test(df$ug_accept[df$ug_p2_copartisan==1&df$pol==1&df$country=="CH"],df$ug_accept[df$ug_p2_copartisan==0&df$pol==1&df$country=="CH"])
t_acce_pol_coeffect_us<-t.test(df$ug_accept[df$ug_p2_copartisan==1&df$pol==1&df$country=="US"],df$ug_accept[df$ug_p2_copartisan==0&df$pol==1&df$country=="US"])

# input values into data frame for plotting

effect_sizes$value[effect_sizes$Country=="All"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_all$estimate[1]-t_prop_pol_pceffect_all$estimate[2])
effect_sizes$value[effect_sizes$Country=="All"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_all$estimate[1]-t_acce_pol_pceffect_all$estimate[2])
effect_sizes$value[effect_sizes$Country=="All"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-1*(t_prop_pol_coeffect_all$estimate[1]-t_prop_pol_coeffect_all$estimate[2])
effect_sizes$value[effect_sizes$Country=="All"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-1*(t_acce_pol_coeffect_all$estimate[1]-t_acce_pol_coeffect_all$estimate[2])

effect_sizes$value[effect_sizes$Country=="Belgium"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_be$estimate[1]-t_prop_pol_pceffect_be$estimate[2])
effect_sizes$value[effect_sizes$Country=="Canada"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_ca$estimate[1]-t_prop_pol_pceffect_ca$estimate[2])
effect_sizes$value[effect_sizes$Country=="Germany"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_de$estimate[1]-t_prop_pol_pceffect_de$estimate[2])
effect_sizes$value[effect_sizes$Country=="Switzerland"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_ch$estimate[1]-t_prop_pol_pceffect_ch$estimate[2])
effect_sizes$value[effect_sizes$Country=="United States"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_us$estimate[1]-t_prop_pol_pceffect_us$estimate[2])
effect_sizes$value[effect_sizes$Country=="Belgium"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_be$estimate[1]-t_prop_pol_coeffect_be$estimate[2])
effect_sizes$value[effect_sizes$Country=="Canada"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_ca$estimate[1]-t_prop_pol_coeffect_ca$estimate[2])
effect_sizes$value[effect_sizes$Country=="Germany"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_de$estimate[1]-t_prop_pol_coeffect_de$estimate[2])
effect_sizes$value[effect_sizes$Country=="Switzerland"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_ch$estimate[1]-t_prop_pol_coeffect_ch$estimate[2])
effect_sizes$value[effect_sizes$Country=="United States"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_us$estimate[1]-t_prop_pol_coeffect_us$estimate[2])

effect_sizes$value[effect_sizes$Country=="Belgium"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_be$estimate[1]-t_acce_pol_pceffect_be$estimate[2])
effect_sizes$value[effect_sizes$Country=="Canada"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_ca$estimate[1]-t_acce_pol_pceffect_ca$estimate[2])
effect_sizes$value[effect_sizes$Country=="Germany"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_de$estimate[1]-t_acce_pol_pceffect_de$estimate[2])
effect_sizes$value[effect_sizes$Country=="Switzerland"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_ch$estimate[1]-t_acce_pol_pceffect_ch$estimate[2])
effect_sizes$value[effect_sizes$Country=="United States"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_us$estimate[1]-t_acce_pol_pceffect_us$estimate[2])
effect_sizes$value[effect_sizes$Country=="Belgium"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_be$estimate[1]-t_acce_pol_coeffect_be$estimate[2])
effect_sizes$value[effect_sizes$Country=="Canada"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_ca$estimate[1]-t_acce_pol_coeffect_ca$estimate[2])
effect_sizes$value[effect_sizes$Country=="Germany"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_de$estimate[1]-t_acce_pol_coeffect_de$estimate[2])
effect_sizes$value[effect_sizes$Country=="Switzerland"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_ch$estimate[1]-t_acce_pol_coeffect_ch$estimate[2])
effect_sizes$value[effect_sizes$Country=="United States"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_us$estimate[1]-t_acce_pol_coeffect_us$estimate[2])

effect_sizes$cilo[effect_sizes$Country=="All"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_all$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="All"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-1*(t_prop_pol_coeffect_all$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="All"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_all$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="All"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-1*(t_acce_pol_coeffect_all$conf.int[1])

effect_sizes$cilo[effect_sizes$Country=="Belgium"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_be$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Canada"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_ca$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Germany"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_de$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Switzerland"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_ch$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="United States"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_us$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Belgium"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_be$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Canada"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_ca$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Germany"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_de$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Switzerland"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_ch$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="United States"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_us$conf.int[1])

effect_sizes$cilo[effect_sizes$Country=="Belgium"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_be$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Canada"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_ca$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Germany"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_de$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Switzerland"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_ch$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="United States"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_us$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Belgium"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_be$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Canada"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_ca$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Germany"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_de$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="Switzerland"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_ch$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="United States"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_us$conf.int[1])

effect_sizes$cihi[effect_sizes$Country=="All"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_all$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="All"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-1*(t_prop_pol_coeffect_all$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="All"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_all$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="All"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-1*(t_acce_pol_coeffect_all$conf.int[2])

effect_sizes$cihi[effect_sizes$Country=="Belgium"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_be$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Canada"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_ca$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Germany"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_de$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Switzerland"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_ch$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="United States"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_prop_pol_pceffect_us$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Belgium"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_be$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Canada"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_ca$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Germany"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_de$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Switzerland"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_ch$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="United States"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_prop_pol_coeffect_us$conf.int[2])

effect_sizes$cihi[effect_sizes$Country=="Belgium"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_be$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Canada"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_ca$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Germany"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_de$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Switzerland"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_ch$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="United States"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician/Citizen"]<-1*(t_acce_pol_pceffect_us$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Belgium"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_be$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Canada"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_ca$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Germany"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_de$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="Switzerland"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_ch$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="United States"&Quantity=="Demand"&Sample=="Politicians"&Target=="Co-Partisan/Out-Partisan"]<-(1)*(t_acce_pol_coeffect_us$conf.int[2])

effect_sizes$Country<-factor(effect_sizes$Country,levels = c("United States","Switzerland","Germany","Canada","Belgium","All"))  
effect_sizes$Quantity<-factor(effect_sizes$Quantity,levels = c("Proposal","Demand"))  
effect_sizes$Sample<-factor(effect_sizes$Sample,levels = c("Politicians"))  
effect_sizes$Target<-factor(effect_sizes$Target,levels = c("Politician/Citizen","Co-Partisan/Out-Partisan"))  

effect_sizes$effect_label<-NA
effect_sizes$effect_label[effect_sizes$Target=="Politician/Citizen"]<-"Effect:\n Pol.\n Target"
effect_sizes$effect_label[effect_sizes$Target=="Co-Partisan/Out-Partisan"]<-"Effect:\n Co-Par.\n Target"

effect_sizes$quantity_label<-NA
effect_sizes$quantity_label[effect_sizes$Quantity=="Proposal"]<-"Outcome:\n Proposal"
effect_sizes$quantity_label[effect_sizes$Quantity=="Demand"]<-"Outcome:\n Demand"
effect_sizes$quantity_label<-factor(effect_sizes$quantity_label,levels = c("Outcome:\n Proposal","Outcome:\n Demand"))  

effect_sizes_pols<-effect_sizes %>%
  filter(Sample=="Politicians")

effect_sizes_pols$shapenum<-NA
effect_sizes_pols$shapenum<-ifelse(effect_sizes_pols$Target=="Politician/Citizen",16,
                                   ifelse(effect_sizes_pols$Target=="Co-Partisan/Out-Partisan",17,NA))

effect_sizes_pols <- effect_sizes_pols %>%
  filter(Target=="Co-Partisan/Out-Partisan")

# output plot
p_effect_sizes_pols<-ggplot(data=effect_sizes_pols)+
  geom_point(aes(y=Country,x=value),size=3)+
  geom_errorbarh(aes(y=Country,xmin=cilo,xmax=cihi),height=0,size=1)+
  facet_grid(~quantity_label,switch="y")+
  geom_vline(xintercept=0,linetype="dashed")+
  ylab("")+
  xlab("")+
  theme(strip.text.y = element_text(angle = 180,size=12),
        legend.position = "none",
        strip.text.x = element_text(size=12),
        axis.text=element_text(size=12),
        axis.title = element_text(size=12),
        panel.spacing = unit(1, "lines"))+
  scale_x_continuous(limits=c(-300,300),
                     breaks=c(-300,-200,-100,0,100,200,300))
p_effect_sizes_pols
ggsave("p_effect_sizes_pols.eps",p_effect_sizes_pols)
ggsave("p_effect_sizes_pols.pdf",p_effect_sizes_pols)


# FIGURE 3: PARTISANSHIP TREATMENT EFFECTS BY COUNTERPART TYPE 
# ============================================================

# create data frame containing relevant estimates and confidence intervals
Country <- rep(c("All"),4)
Quantity <- c(rep("Proposal",2),rep("Demand",2))
Sample <- rep("Politicians",4)
Target <- rep(c("Politician","Citizen"),2)
value <- rep(NA,4)
cilo <- rep(NA,4)
cihi <- rep(NA,4)

effect_sizes <- data.frame(Country,Quantity,Sample,Target,value,cilo,cihi)

# extract values of quantity change in proposals and demands by partisanship treatment condition, for each target type (politician/citizen)
t_prop_pol_coeffect_pols_all<-t.test(df$ug_propose[df$ug_p2_copartisan==1&df$pol==1&df$ug_p2_politician==1],df$ug_propose[df$ug_p2_copartisan==0&df$pol==1&df$ug_p2_politician==1])
t_prop_pol_coeffect_cits_all<-t.test(df$ug_propose[df$ug_p2_copartisan==1&df$pol==1&df$ug_p2_politician==0],df$ug_propose[df$ug_p2_copartisan==0&df$pol==1&df$ug_p2_politician==0])
t_acce_pol_coeffect_pols_all<-t.test(df$ug_accept[df$ug_p2_copartisan==1&df$pol==1&df$ug_p2_politician==1],df$ug_accept[df$ug_p2_copartisan==0&df$pol==1&df$ug_p2_politician==1])
t_acce_pol_coeffect_cits_all<-t.test(df$ug_accept[df$ug_p2_copartisan==1&df$pol==1&df$ug_p2_politician==0],df$ug_accept[df$ug_p2_copartisan==0&df$pol==1&df$ug_p2_politician==0])

effect_sizes$value[effect_sizes$Country=="All"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician"]<-1*(t_prop_pol_coeffect_pols_all$estimate[1]-t_prop_pol_coeffect_pols_all$estimate[2])
effect_sizes$value[effect_sizes$Country=="All"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Citizen"]<-1*(t_prop_pol_coeffect_cits_all$estimate[1]-t_prop_pol_coeffect_cits_all$estimate[2])
effect_sizes$value[effect_sizes$Country=="All"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician"]<-1*(t_acce_pol_coeffect_pols_all$estimate[1]-t_acce_pol_coeffect_pols_all$estimate[2])
effect_sizes$value[effect_sizes$Country=="All"&Quantity=="Demand"&Sample=="Politicians"&Target=="Citizen"]<-1*(t_acce_pol_coeffect_cits_all$estimate[1]-t_acce_pol_coeffect_cits_all$estimate[2])

effect_sizes$cilo[effect_sizes$Country=="All"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician"]<-1*(t_prop_pol_coeffect_pols_all$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="All"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Citizen"]<-1*(t_prop_pol_coeffect_cits_all$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="All"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician"]<-1*(t_acce_pol_coeffect_pols_all$conf.int[1])
effect_sizes$cilo[effect_sizes$Country=="All"&Quantity=="Demand"&Sample=="Politicians"&Target=="Citizen"]<-1*(t_acce_pol_coeffect_cits_all$conf.int[1])

effect_sizes$cihi[effect_sizes$Country=="All"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Politician"]<-1*(t_prop_pol_coeffect_pols_all$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="All"&Quantity=="Proposal"&Sample=="Politicians"&Target=="Citizen"]<-1*(t_prop_pol_coeffect_cits_all$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="All"&Quantity=="Demand"&Sample=="Politicians"&Target=="Politician"]<-1*(t_acce_pol_coeffect_pols_all$conf.int[2])
effect_sizes$cihi[effect_sizes$Country=="All"&Quantity=="Demand"&Sample=="Politicians"&Target=="Citizen"]<-1*(t_acce_pol_coeffect_cits_all$conf.int[2])

effect_sizes$Country<-factor(effect_sizes$Country,levels = c("All"))  
effect_sizes$Quantity<-factor(effect_sizes$Quantity,levels = c("Proposal","Demand"))  
effect_sizes$Sample<-factor(effect_sizes$Sample,levels = c("Politicians","Non-Politicians"))  
effect_sizes$Target<-factor(effect_sizes$Target,levels = c("Politician","Citizen"))  

effect_sizes$effect_label<-NA
effect_sizes$effect_label[effect_sizes$Target=="Politician"]<-"Politician\n Target"
effect_sizes$effect_label[effect_sizes$Target=="Citizen"]<-"Citizen\n Target"

effect_sizes$quantity_label<-NA
effect_sizes$quantity_label[effect_sizes$Quantity=="Proposal"]<-"Outcome:\n Proposal"
effect_sizes$quantity_label[effect_sizes$Quantity=="Demand"]<-"Outcome:\n Demand"
effect_sizes$quantity_label<-factor(effect_sizes$quantity_label,levels = c("Outcome:\n Proposal","Outcome:\n Demand"))  

effect_sizes_pols<-effect_sizes %>%
  filter(Sample=="Politicians")

# output plot
p_effect_sizes_interaction_pols<-ggplot(data=effect_sizes_pols)+
  geom_point(aes(y=effect_label,x=value),size=4,shape=16)+
  geom_errorbarh(aes(y=effect_label,xmin=cilo,xmax=cihi),height=0,size=1)+
  facet_grid(~quantity_label,switch="y")+
  geom_vline(xintercept=0,linetype="dashed")+
  ylab("")+
  xlab("")+
  theme(strip.text.y = element_text(angle = 180),
        strip.text.x = element_text(size=16),
        axis.text=element_text(size=16),
        axis.title = element_text(size=16))+
  scale_x_continuous(limits=c(-220,220),
                     breaks=c(-200,-100,0,100,200))+
  scale_y_discrete(expand=c(0.3, 0.3),drop=FALSE)+
  coord_fixed(ratio=150)
p_effect_sizes_interaction_pols
ggsave("p_effect_sizes_interaction_pols.eps",p_effect_sizes_interaction_pols,width=12,height=6)
ggsave("p_effect_sizes_interaction_pols.pdf",p_effect_sizes_interaction_pols,width=12,height=6)


# 2. REPLICATION CODE FOR ONLINE SUPPLEMENTARY MATERIAL TABLES AND FIGURES
# ========================================================================
# ========================================================================



# TABLE A.2: COUNTERPART TREATMENT RESULTS
# ========================================

ug_p2_politician_all_nocountry<-df %>%
  filter(!is.na(ug_propose)) %>%
  filter(pol==1) %>%
  group_by(ug_p2_politician_labelled) %>%
  summarise(country_name="All",propose_mean = mean(ug_propose,na.rm=TRUE),
            accept_mean= mean(ug_accept,na.rm=TRUE),
            N = n()) 
ug_p2_politician_all_nocountry<-ug_p2_politician_all_nocountry[,c(2,1,3,4,5)]
ug_p2_politician_all_nocountry$N<-as.character(ug_p2_politician_all_nocountry$N)
difference_p2_politician_all_everyone <- ug_p2_politician_all_nocountry %>%
  mutate(propose_mean = propose_mean - lag(propose_mean),
         accept_mean = accept_mean - lag(accept_mean),
         ug_p2_politician_labelled = "Difference",
         N = "-") %>%
  na.omit() 
ug_p2_politician_all_nocountry<-ug_p2_politician_all_nocountry %>%
  bind_rows(difference_p2_politician_all_everyone) 

ug_p2_politician_all<-df %>%
  filter(!is.na(ug_propose)) %>%
  filter(pol==1) %>%
  group_by(country_name,ug_p2_politician_labelled) %>%
  summarise(propose_mean = mean(ug_propose,na.rm=TRUE),
            accept_mean= mean(ug_accept,na.rm=TRUE),
            N = n()) 
ug_p2_politician_all$N<-as.character(ug_p2_politician_all$N)
difference_p2_politician_all <- ug_p2_politician_all %>%
  group_by(country_name) %>%
  mutate(propose_mean = propose_mean - lag(propose_mean),
         accept_mean = accept_mean - lag(accept_mean),
         ug_p2_politician_labelled = "Difference",
         N = "-") %>%
  na.omit() 
ug_p2_politician_all<-ug_p2_politician_all %>%
  bind_rows(difference_p2_politician_all) %>%
  arrange(country_name)
ug_p2_politician_all<-bind_rows(ug_p2_politician_all_nocountry,ug_p2_politician_all)
ug_p2_politician_all$country_name<-as.character(ug_p2_politician_all$country_name)
ug_p2_politician_all$country_name[ug_p2_politician_all$ug_p2_politician_labelled=="Politician"|ug_p2_politician_all$ug_p2_politician_labelled=="Difference"]<-" "

stargazer(as.data.frame(ug_p2_politician_all),summary=FALSE,single.row = TRUE,
          table.placement = "H",label = "ug_p2_politician_all", digits=0,rownames = FALSE,
          covariate.labels = c("Country","Target","Mean Proposal","Mean Demand","N"))



# TABLE A.3: PER COUNTRY PROPOSE MODELS
# =====================================


# models
m_all_p_be<-lm(data=subset(df,pol==1 & country == "BE"),ug_propose ~ ug_p2_copartisan + ug_propose_first)
m_all_p_ca<-lm(data=subset(df,pol==1 & country == "CA"),ug_propose ~ ug_p2_copartisan + ug_propose_first)
m_all_p_de<-lm(data=subset(df,pol==1 & country == "DE"),ug_propose ~ ug_p2_copartisan + ug_propose_first)
m_all_p_ch<-lm(data=subset(df,pol==1 & country == "CH"),ug_propose ~ ug_p2_copartisan + ug_propose_first)
m_all_p_us<-lm(data=subset(df,pol==1 & country == "US"),ug_propose ~ ug_p2_copartisan + ug_propose_first)
m_all_p_p2p_be<-lm(data=subset(df,pol==1 & country == "BE"),ug_propose ~ ug_p2_copartisan + ug_p2_politician + ug_propose_first)
m_all_p_p2p_ca<-lm(data=subset(df,pol==1 & country == "CA"),ug_propose ~ ug_p2_copartisan + ug_p2_politician + ug_propose_first)
m_all_p_p2p_de<-lm(data=subset(df,pol==1 & country == "DE"),ug_propose ~ ug_p2_copartisan + ug_p2_politician + ug_propose_first)
m_all_p_p2p_ch<-lm(data=subset(df,pol==1 & country == "CH"),ug_propose ~ ug_p2_copartisan + ug_p2_politician + ug_propose_first)
m_all_p_p2p_us<-lm(data=subset(df,pol==1 & country == "US"),ug_propose ~ ug_p2_copartisan + ug_p2_politician + ug_propose_first)

# the output tables below are merged manually in latex for the manuscript
stargazer(m_all_p_be,
          m_all_p_p2p_be,
          m_all_p_ca,
          m_all_p_p2p_ca,
          single.row = FALSE,no.space = TRUE,model.numbers = FALSE,
          dep.var.caption = "",dep.var.labels.include = FALSE,
          table.placement = "H",label = "h1_h2_models_propose", digits=2,
          omit.stat = c("rsq","adj.rsq","ser","f"),
          column.labels = c("Belgium","Canada"),
          column.separate=c(2,2),
          covariate.labels = c("Co-partisan Target","Politician Target","Propose First",
                               "Intercept"))
stargazer(m_all_p_de,
          m_all_p_p2p_de,
          m_all_p_ch,
          m_all_p_p2p_ch,
          single.row = FALSE,no.space = TRUE,model.numbers = FALSE,
          dep.var.caption = "",dep.var.labels.include = FALSE,
          table.placement = "H",label = "h1_h2_models_propose", digits=2,
          omit.stat = c("rsq","adj.rsq","ser","f"),
          column.labels = c("Germany","Switzerland"),
          column.separate=c(2,2),
          covariate.labels = c("Co-partisan Target","Politician Target","Propose First",
                               "Intercept"))

stargazer(m_all_p_us,
          m_all_p_p2p_us,
          single.row = FALSE,no.space = TRUE,model.numbers = FALSE,
          dep.var.caption = "",dep.var.labels.include = FALSE,
          table.placement = "H",label = "h1_h2_models_propose", digits=2,
          omit.stat = c("rsq","adj.rsq","ser","f"),
          column.labels = c("United States"),
          column.separate=c(2,2),
          covariate.labels = c("Co-partisan Target","Politician Target","Propose First",
                               "Intercept"))


# TABLE A.4: PER COUNTRY DEMAND MODELS
# ====================================

# models
m_all_a<-lm(data=subset(df,pol==1),ug_accept ~ ug_p2_copartisan + ug_propose_first + country)
m_all_a_p2p<-lm(data=subset(df,pol==1),ug_accept ~ ug_p2_copartisan + ug_p2_politician + ug_propose_first + country)
m_all_a_be<-lm(data=subset(df,pol==1 & country == "BE"),ug_accept ~ ug_p2_copartisan + ug_propose_first)
m_all_a_ca<-lm(data=subset(df,pol==1 & country == "CA"),ug_accept ~ ug_p2_copartisan + ug_propose_first)
m_all_a_de<-lm(data=subset(df,pol==1 & country == "DE"),ug_accept ~ ug_p2_copartisan + ug_propose_first)
m_all_a_ch<-lm(data=subset(df,pol==1 & country == "CH"),ug_accept ~ ug_p2_copartisan + ug_propose_first)
m_all_a_us<-lm(data=subset(df,pol==1 & country == "US"),ug_accept ~ ug_p2_copartisan + ug_propose_first)
m_all_a_p2p_be<-lm(data=subset(df,pol==1 & country == "BE"),ug_accept ~ ug_p2_copartisan + ug_p2_politician + ug_propose_first)
m_all_a_p2p_ca<-lm(data=subset(df,pol==1 & country == "CA"),ug_accept ~ ug_p2_copartisan + ug_p2_politician + ug_propose_first)
m_all_a_p2p_de<-lm(data=subset(df,pol==1 & country == "DE"),ug_accept ~ ug_p2_copartisan + ug_p2_politician + ug_propose_first)
m_all_a_p2p_ch<-lm(data=subset(df,pol==1 & country == "CH"),ug_accept ~ ug_p2_copartisan + ug_p2_politician + ug_propose_first)
m_all_a_p2p_us<-lm(data=subset(df,pol==1 & country == "US"),ug_accept ~ ug_p2_copartisan + ug_p2_politician + ug_propose_first)

# the output tables below are merged manually in latex for the manuscript
stargazer(m_all_a_be,
          m_all_a_p2p_be,
          m_all_a_ca,
          m_all_a_p2p_ca,
          single.row = FALSE,no.space = TRUE,model.numbers = FALSE,
          dep.var.caption = "",dep.var.labels.include = FALSE,
          table.placement = "H",label = "h1_h2_models_accept", digits=2,
          omit.stat = c("rsq","adj.rsq","ser","f"),
          column.labels = c("Belgium","Canada"),
          column.separate=c(2,2),
          covariate.labels = c("Co-partisan Target","Politician Target","Propose First",
                               "Intercept"))

stargazer(m_all_a_de,
          m_all_a_p2p_de,
          m_all_a_ch,
          m_all_a_p2p_ch,
          single.row = FALSE,no.space = TRUE,model.numbers = FALSE,
          dep.var.caption = "",dep.var.labels.include = FALSE,
          table.placement = "H",label = "h1_h2_models_accept", digits=2,
          omit.stat = c("rsq","adj.rsq","ser","f"),
          column.labels = c("Germany","Switzerland"),
          column.separate=c(2,2),
          covariate.labels = c("Co-partisan Target","Politician Target","Propose First",
                               "Intercept"))

stargazer(m_all_a_us,
          m_all_a_p2p_us,
          single.row = FALSE,no.space = TRUE,model.numbers = FALSE,
          dep.var.caption = "",dep.var.labels.include = FALSE,
          table.placement = "H",label = "h1_h2_models_accept", digits=2,
          omit.stat = c("rsq","adj.rsq","ser","f"),
          column.labels = c("United States"),
          column.separate=c(2,2),
          covariate.labels = c("Co-partisan Target","Politician Target","Propose First",
                               "Intercept"))


# TABLE A.5: PER COUNTRY PROPOSE INTERACTION MODELS
# =================================================

# propose models for per-country treatment interactions
m_p_int_be<-lm(data=subset(df,pol==1 & country == "BE"),ug_propose ~ ug_p2_copartisan* ug_p2_politician  + ug_propose_first)
m_p_int_ca<-lm(data=subset(df,pol==1 & country == "CA"),ug_propose ~ ug_p2_copartisan* ug_p2_politician + ug_propose_first)
m_p_int_de<-lm(data=subset(df,pol==1 & country == "DE"),ug_propose ~ ug_p2_copartisan* ug_p2_politician + ug_propose_first)
m_p_int_ch<-lm(data=subset(df,pol==1 & country == "CH"),ug_propose ~ ug_p2_copartisan* ug_p2_politician + ug_propose_first)
m_p_int_us<-lm(data=subset(df,pol==1 & country == "US"),ug_propose ~ ug_p2_copartisan* ug_p2_politician + ug_propose_first)

stargazer(m_p_int_be,
          m_p_int_ca,
          m_p_int_de,
          m_p_int_ch,
          m_p_int_us,
          single.row = FALSE,no.space = TRUE,model.numbers = FALSE,
          dep.var.caption = "",dep.var.labels.include = FALSE,
          table.placement = "H",label = "models_propose_interaction", digits=2,
          omit.stat = c("rsq","adj.rsq","ser","f"),
          column.labels = c("BE","CA","DE","CH","US"),
          covariate.labels = c("Co-partisan Target","Politician Target","Propose First","Co-Partisan X Politician",
                               "Intercept"))



# TABLE A.6: PER COUNTRY DEMAND INTERACTION MODELS
# ================================================

# demand models for per-country treatment interactions
m_a_int_be<-lm(data=subset(df,pol==1 & country == "BE"),ug_accept ~ ug_p2_copartisan* ug_p2_politician + ug_propose_first)
m_a_int_ca<-lm(data=subset(df,pol==1 & country == "CA"),ug_accept ~ ug_p2_copartisan* ug_p2_politician + ug_propose_first)
m_a_int_de<-lm(data=subset(df,pol==1 & country == "DE"),ug_accept ~ ug_p2_copartisan* ug_p2_politician + ug_propose_first)
m_a_int_ch<-lm(data=subset(df,pol==1 & country == "CH"),ug_accept ~ ug_p2_copartisan* ug_p2_politician + ug_propose_first)
m_a_int_us<-lm(data=subset(df,pol==1 & country == "US"),ug_accept ~ ug_p2_copartisan* ug_p2_politician + ug_propose_first)

stargazer(m_a_int_be,
          m_a_int_ca,
          m_a_int_de,
          m_a_int_ch,
          m_a_int_us,
          single.row = FALSE,no.space = TRUE,model.numbers = FALSE,
          dep.var.caption = "",dep.var.labels.include = FALSE,
          table.placement = "H",label = "models_accept_interaction", digits=2,
          omit.stat = c("rsq","adj.rsq","ser","f"),
          column.labels = c("BE","CA","DE","CH","US"),
          covariate.labels = c("Co-partisan Target","Politician Target","Propose First","Co-Partisan X Politician",
                               "Intercept"))


# TABLE A.8: CALIBRATION ANALYSIS
# ===============================

# table created manually in latex using the figures obtained form the following commands:

df %>%
  filter(ug_p2_politician==1) %>%
  filter(!is.na(ug_p2_copartisan)) %>%
  group_by(ug_p2_copartisan) %>%
  summarise(mean_prop = mean(ug_propose,na.rm=TRUE),
            mean_acc = mean(ug_accept,na.rm=TRUE),
            mean_diff = mean(ug_propose-ug_accept,na.rm=TRUE),
            n())

df %>%
  filter(ug_p2_politician==1) %>%
  filter(!is.na(ug_p2_copartisan)) %>%
  summarise(mean_prop = mean(ug_propose,na.rm=TRUE),
            mean_acc = mean(ug_accept,na.rm=TRUE),
            mean_diff = mean(ug_propose-ug_accept,na.rm=TRUE),
            n())


# FIGURE A.1: DISTRIBUTION PLOT OF RESPONSES - PROPOSALS
# ======================================================

ug_propose_density_by_co_country <- ggplot(data=subset(df,!is.na(df$ug_p2_copartisan_labelled)))+geom_density(aes(x=ug_propose),adjust=0.9)+
  facet_grid(country_name~ug_p2_copartisan_labelled,scales="free",switch="y")+
  theme(aspect.ratio=0.6,
        axis.text.x=element_text(angle=45))+
  xlab("Proposal Value")+
  ylab("Density\n")
ug_propose_density_by_co_country
ggsave("ug_propose_density_by_co_country.eps",ug_propose_density_by_co_country)
ggsave("ug_propose_density_by_co_country.pdf",ug_propose_density_by_co_country)


# FIGURE A.2: DISTRIBUTION PLOT OF RESPONSES - DEMANDS
# ====================================================

ug_demand_density_by_co_country<- ggplot(data=subset(df,!is.na(df$ug_p2_copartisan_labelled)))+geom_density(aes(x=ug_accept),adjust=0.5)+
  facet_grid(country_name~ug_p2_copartisan_labelled,scales="free",switch="y")+
  theme(aspect.ratio=0.6,
        axis.text.x=element_text(angle=45))+
  xlab("Demand Value")+
  ylab("Density\n")
ug_demand_density_by_co_country
ggsave("ug_demand_density_by_co_country.eps",ug_demand_density_by_co_country)
ggsave("ug_demand_density_by_co_country.pdf",ug_demand_density_by_co_country)



